<?php

class WebCLIRequest extends WebGlobalRequest {
	private function setGETAndQueryString($v) {
		$this->setQueryString($v);
		$v = explode('&', $v);
		foreach ($v as $x) {
			$name = $x; $value = '';
			if (($pos = strrpos($x, '=')) !== false) {
				$name = substr($x, 0, $pos);
				$value = substr($x, $pos + 1);
			}
			
			$this->addGETVariable($name, $value);
		}
	}
	
	function __construct() {
		parent::__construct();
		
		global $argv, $argc;
		for ($i = 1; $i < $argc; $i++) {
			$arg = $argv[$i];
			
			if (($pos = strpos($arg, '=')) !== false) {
				$name = substr($arg, 0, $pos);
				$value = substr($arg, $pos + 1);
				
				// var_dump($name);
				// var_dump($value);
				
				if ($name == '__pathInfo')
					$this->setPathInfo($value);
				else if ($name == '__user')
					$this->setUserName($value);
				else if ($name == '__password')
					$this->setPassword($value);
				else if ($name == '__method')
					$this->setMethod($value);
				else if ($name == '__queryString')
					$this->setGETAndQueryString($value);
				else if (($cookieName = CSuffixIfPrefixIs($name, '__cookie_')) !== false)
					$this->addCookie($cookieName, $value);
				else if (($postName = CSuffixIfPrefixIs($name, '__post_')) !== false)
					$this->addPOSTVariable($postName, $value);
				else
					$this->addGETVariable($name, $value);
			}
		}
	}
	
	public static function instance() {
		static $myself = null;
		if (!$myself) $myself = new WebCLIRequest();
		return $myself;
	}
}

?>